<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="avicit.platform6.commons.utils.ViewUtil"%>
<%@page import="avicit.platform6.core.locale.PlatformLocalesJSTL"%>
<%@page import="java.util.Locale"%>
<%@page import="avicit.platform6.api.session.SessionHelper"%>
<%@page import="avicit.platform6.api.sysshirolog.impl.AfterLoginSessionProcess"%>
<%
    Object lang=session.getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
    String languageCode="zh_CN";
    if(lang!=null){
        languageCode=lang.toString();
    }
    Locale locale =SessionHelper.getLocaleByUser(request);
%>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>报表配置</title>
    <base href="<%=ViewUtil.getRequestPath(request)%>">

    <jsp:include page="/avicit/platform6/component/common/EasyUIJsInclude.jsp"></jsp:include>
    <jsp:include page="/avicit/im/common/ImUIJSCSSInclude.jsp"></jsp:include>
    <script type="text/javascript" src="avicit/im/lantop/basic/reportmanager/js/ReportFormConfig.js"></script>
    <script type="text/javascript" src="avicit/im/lantop/basic/reportmanager/locale/language_<%=languageCode%>.js"></script>
</head>
<script type="text/javascript">
    var baseurl = "<%=ViewUtil.getRequestPath(request)%>";
    var dialogId = '${dialogId}'; //打开页面传递的模块ID
    var datagridId = "${datagridId}";
    var templateId = "${templateId}";
    var resultDataSource = "${resultDataSource}";

    var colNamesDataGrid ;
    var columnsDataGrid ;
    var outputFields = [];
    var fields ;
    var fieldsCount;
    var sql ;

    var nodesFieldIndex = {};

    var commArgs = parent.reportManager.getCommArgs();

    $(function(){
        fields = '${outputFields}';
        fieldCount = Number('${fieldsCount}');
        colNamesDataGrid = $("#colNamesDataGrid");
        columnsDataGrid = $("#columnsDataGrid");
        columnsDataGrid.datagrid({
            onSelect : function(rowIndex, rowData){
                columnsDataGrid.datagrid('highlightRow', rowIndex);
            }

        });
        $('#classTree').tree({
            checkbox : true, 						/* 是否带复选框 */
            onlyLeafCheck : true,
            cascadeCheck : false,
            lines : true, 							/* 线条 */
            method : 'post' 						/* 请求数据方式 */,
            url : 'platform/ReportFormConfigController/findChildsByNodeId', /* 请求数据地址 */
            dataType : "json", /* 数据格式 */
            onClick : function(node) {

            },
            onCheck : function(node, checked){
                var checkNodes = ($('#classTree').tree('getChecked'));
                if(checkNodes.length == 0){
                    $("#columnsDataGrid").datagrid('loadData', []);
                    $("#colNamesDataGrid").datagrid('loadData', []);
                    // 清除应输出字段
                    $("#currOutput").val('');
                    return ;
                }
                var nodes = [];
                $.each(checkNodes, function(index, node){
                    if(node.attributes.ARCHIVE_TYPE != '-1' && node.attributes.ARCHIVE_TYPE != null && node.attributes.ARCHIVE_TYPE != '0'){
                        nodes.push(node);
                    }
                });
                if(nodes.length == 0){
                    return ;
                }
                if(nodes.length >= 2){
                    //'提示', '所选的节点不在同一目录下，不能进行选择！'
                    $.messager.alert("<%=PlatformLocalesJSTL.getBundleValue("lantop.remind","i18n.lantop",locale)%>", "<%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.nochoose","i18n.lantop",locale)%>", 'warning');
                    $("#classTree").tree('uncheck', node.target);
                    return ;
                }
                onClickRowEvent(nodes);
            },
            loadFilter : function(data) {
                // 过滤后台返回的数据，处理不同json结构
                if (data.data) {
                    return data.data;
                } else {
                    return data;
                }
            },
            onContextMenu : function(e, node) {
                // 树节点右击菜单
                e.preventDefault();
                $(this).tree('select', node.target);
                //showMenu(node, e);
            },
            onLoadSuccess : function() {
                var node = $("#classTree").tree("getRoot");
                if (node != null) {
                    $("#classTree").tree("select", node.target);
                }

            },
            onSelect : function(node) {

            },
            formatter : function(node) {
                return '<span title="' + node.text + '">' + node.text + '</span>';
            }
        });
    });

    // 点击的节点刷新iframe
    function onClickRowEvent(node) {
        $.ajax({
            url : 'platform/ReportFormConfigController/getTableList',
            type : 'post',
            dataType : 'json',
            data : {
                nodeId: node[0].id,
                sysId : commArgs.sysId,
                resultDataSource : resultDataSource,
                templateId : templateId

            },
            success : function(result){
                // 显示具体内容
                $("#columnsDataGrid").datagrid('loadData', []);
                $.each(result.rows, function(index, row){
                    $("#columnsDataGrid").datagrid("appendRow",row);

                });
                $("#colNamesDataGrid").datagrid('loadData', []);
                // 显示已经配置的字段
                $.each(result.setFields, function(index, row){
                    $("#colNamesDataGrid").datagrid("appendRow",row);
                });
                getCurrColumnForCurrOutput();

            }
        });
    }

    function formatterField(value, row, index) {
        var colName = row.COL_NAME;
        if(colName == undefined || colName == null || colName == "" ){
            return value;
        }
        return row.TABLE_TITLE + "." + value;
    }
</script>
<body class="easyui-layout" fit="true">
<div region="north" border="false" style="height: 0; border: false; height: 100px;">
    <table class="form_commonTable">
        <tr>
            <%--报表应输出字段： --%>
            <th width="20%" align="right"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.reportshouldoutputfields","i18n.lantop",locale)%></th>
            <td class="input-readonly">
                <input id="output" class="easyui-validatebox input-readonly" value="${outputFields} " readonly="true" />
            </td>
        </tr>
        <tr>
            <%--实际应输出字段： --%>
            <th width="20%" align="right"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.reportinfactoutputfields","i18n.lantop",locale)%></th>
            <td class="input-readonly">
                <input id="currOutput" class="easyui-validatebox input-readonly" data-options="required:true" readonly="true" />
            </td>

        </tr>
    </table>
</div>
<!-- 加载树 -->
<div data-options="region:'west',split:false" style="width: 170px;">
    <ul id="classTree"></ul>
</div>
<div data-options="region:'center',border:false" overflow-y:auto;">
<div id="cc" class="easyui-layout" fit="true">
    <div data-options="region:'east',iconCls:'icon-reload',noheader:true,split:false" style="width: 450px;">
        <table id="colNamesDataGrid" class="easyui-datagrid"
               data-options="fit:true,
						animate: true,
						collapsible: false,
						fitColumns: true,
						autoRowHeight: false,
						singleSelect: true,
						striped:true,
						rownumbers: true,
						method: 'post',
						rowStyler: rowColor,
						remoteSort : false
					">
            <thead>
            <tr>
                <sec:accesscontrollist hasPermission="3" domainObject="excel_export_datagrid_id">
                    <%--表名--%>
                    <th data-options="field:'TABLE_NAME',  hidden:true ,  halign:'center', align:'center', sortable:false" width="200" title="表名"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.tablename","i18n.lantop",locale)%></th>
                </sec:accesscontrollist>

                <sec:accesscontrollist hasPermission="3" domainObject="excel_export_datagrid_id">
                    <%--表名--%>
                    <th data-options="field:'TABLE_TITLE',  hidden:true ,  halign:'center', align:'center', sortable:false" width="200" title="表名"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.tablename","i18n.lantop",locale)%></th>
                </sec:accesscontrollist>

                <sec:accesscontrollist hasPermission="3" domainObject="excel_export_datagrid_id">
                    <%--字段名称--%>
                    <th data-options="field:'COL_NAME',  hidden:true , halign:'center', align:'center', sortable:false" width="200" title="字段名称"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.filedname","i18n.lantop",locale)%></th>
                </sec:accesscontrollist>

                <sec:accesscontrollist hasPermission="3" domainObject="excel_export_choose_datagrid_colName">
                    <%--字段名称--%>
                    <th data-options="field:'COL_LABEL', halign:'center', align:'center', sortable:false,formatter:formatterField" width="200" title="字段名称"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.filedname","i18n.lantop",locale)%></th>
                </sec:accesscontrollist>
            </tr>
            </thead>
        </table>
    </div>

    <div id="center" data-options="region:'center',title:'center title', noheader:true,split:false" style="padding: 5px; background: #eee;">
        <table align="center">
            <tr>
                <td>
                    <sec:accesscontrollist hasPermission="3" domainObject="excel_export_button_oneAdd">
                        <%-- 选值右移 --%>
                        <input type="button" style="width: 60px; text-align: 'center';" title="<%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.valuerightmove","i18n.lantop",locale)%>" onclick="oneAdd();" value="【 >】" href="javascript:void(0);"></input>
                    </sec:accesscontrollist>
                </td>
            </tr>
            <tr>
                <td>
                    <sec:accesscontrollist hasPermission="3" domainObject="excel_export_button_allAdd">
                        <%-- 全右移 --%>
                        <input type="button" style="width: 60px; text-align: 'center';" title="<%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.allvaluerightmove","i18n.lantop",locale)%>" onclick="allAdd();" value="【>>】" href="javascript:void(0);"></input>
                    </sec:accesscontrollist>
                </td>
            </tr>
            <tr>
                <td>
                    <sec:accesscontrollist hasPermission="3" domainObject="excel_export_button_oneRemove">
                        <%-- 选值左移 --%>
                        <input type="button" style="width: 60px; text-align: 'center';" title="<%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.valueleftmove","i18n.lantop",locale)%>" onclick="oneRemove();" value="【 <】" href="javascript:void(0);"></input>
                    </sec:accesscontrollist>
                </td>
            </tr>
            <tr>
                <td>
                    <sec:accesscontrollist hasPermission="3" domainObject="excel_export_button_allRemove">
                        <input type="button" style="width: 60px; text-align: 'center';" onclick="allRemove();" value="【<<】" href="javascript:void(0);"></input>
                    </sec:accesscontrollist>
                </td>
            </tr>

        </table>
    </div>
    <div data-options="region:'west',noheader:true,split:false" style="width: 450px;">
        <table id="columnsDataGrid" class="easyui-datagrid"
               data-options="fit:true,
						animate: true,
						collapsible: false,
						fitColumns: true,
						autoRowHeight: false,
						singleSelect: true,
						striped:true,
						method: 'post',
						rownumbers: true,
						onDblClickRow: oneAdd,
						rowStyler: rowColor,
						remoteSort : true,
						url : 'platform/ReportFormConfigController/getTableList'
					">
            <thead>
            <tr>
                <sec:accesscontrollist hasPermission="3" domainObject="excel_export_datagrid_id">
                    <%--表名--%>
                    <th data-options="field:'TABLE_NAME',  hidden:true ,  halign:'center', align:'center', sortable:false" width="200" title="表名"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.tablename","i18n.lantop",locale)%></th>
                </sec:accesscontrollist>
                <sec:accesscontrollist hasPermission="3" domainObject="excel_export_datagrid_id">
                    <%--字段名称--%>
                    <th data-options="field:'TABLE_TITLE',  hidden:true , halign:'center', align:'center', sortable:false" width="200" title="字段名称"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.filedname","i18n.lantop",locale)%></th>
                </sec:accesscontrollist>
                <sec:accesscontrollist hasPermission="3" domainObject="excel_export_datagrid_id">
                    <%--字段名称--%>
                    <th data-options="field:'COL_NAME',  hidden:true , halign:'center', align:'center', sortable:false" width="200" title="字段名称"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.filedname","i18n.lantop",locale)%></th>
                </sec:accesscontrollist>
                <sec:accesscontrollist hasPermission="3" domainObject="excel_export_column_datagrid_colName">
                    <%--字段名称--%>
                    <th data-options="title:'', field:'COL_LABEL', halign:'center', align:'center', sortable:false,formatter:formatterField" width="200" title="字段名称"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.filedname","i18n.lantop",locale)%></th>
                </sec:accesscontrollist>
            </tr>
            </thead>
        </table>
    </div>
</div>
</div>
<div data-options="region:'south',border:false" style="height: 40px;">
    <div id="toolbar" class="datagrid-toolbar datagrid-toolbar-extend foot-formopera">
        <table class="tableForm" border="0" cellspacing="1" width="100%">
            <tr>
                <td align="right">
                    <sec:accesscontrollist hasPermission="3" domainObject="excel_export_button_exportData">
                        <%--保存--%>
                        <a id="saveBtn" title="<%=PlatformLocalesJSTL.getBundleValue("lantop.save","i18n.lantop",locale)%>" data-options="disabled:false" class="easyui-linkbutton primary-btn" onclick="save();" href="javascript:void(0);"><%=PlatformLocalesJSTL.getBundleValue("lantop.save","i18n.lantop",locale)%></a>
                    </sec:accesscontrollist>
                    <sec:accesscontrollist hasPermission="3" domainObject="excel_export_button_cancle">
                        <%--返回--%>
                        <a id="cancleBtn" title="<%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.return","i18n.lantop",locale)%>" class="easyui-linkbutton" onclick="cancle();" href="javascript:void(0);"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.reportformconfig.return","i18n.lantop",locale)%></a>
                    </sec:accesscontrollist>
                </td>
            </tr>
        </table>
    </div>
</div>
</body>
</html>